package com.visikard.asynctask;

import android.os.Handler;

import com.visikard.application.UIMessage;
import com.visikard.business.AccountBUS;
import com.visikard.response.BaseResponse;
import com.visikard.response.LogoutResponse;

public class LogoutTask extends BaseTask {

	public static final int POS_UID = 0;
	public static final int POS_LOGIN_SESSION = 1;

	public LogoutTask(Handler handler) {
		super(handler);
	}

	public LogoutTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {

		Long uid = (Long) params[POS_UID];
		String loginSession = (String) params[POS_LOGIN_SESSION];

		AccountBUS busObj = new AccountBUS();
		return busObj.logout(uid, loginSession);
	}

	@Override
	protected boolean handleResult(Object result) {
		LogoutResponse response = (LogoutResponse) result;
		if (response != null) {
			switch (response.getErrorCode()) {
				case BaseResponse.SUCCESS:
					mUIHandler.sendEmptyMessage(UIMessage.MSG_LOGOUT);
					return true;
			}
		}
		return false;
	}

}
